package cn.moukou.tongji.ihealth.predication.service;

import cn.moukou.tongji.ihealth.predication.config.NettyConfig;
import io.netty.channel.Channel;
import io.netty.handler.codec.http.websocketx.TextWebSocketFrame;
import org.springframework.stereotype.Service;

@Service
public class NettyService {

    public void pushPredicationToAll(String msg) {
        System.out.println(NettyConfig.getChannelGroup().size());
        for (Channel channel : NettyConfig.getChannelGroup()) {
            channel.writeAndFlush(new TextWebSocketFrame(msg));
        }
    }

    public void pushPredictionToUser(String uid, String msg) {
        System.out.println(NettyConfig.getUserChannelMap().size());
        Channel channel = NettyConfig.getUserChannelMap().get(uid);
        if(channel!=null) {
            channel.writeAndFlush(new TextWebSocketFrame(msg));
        }
    }

}
